<!doctype HTML public "-//W3C//DTD HTML 4.0 Frameset//EN">
<html>
<title>Bloomberg Development Environment</title>
<html>
<pre>
// Copyright 2014-2023 Bloomberg Finance L.P.
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// bmqt_queueflags.h                                                  -*-C++-*-
#ifndef INCLUDED_BMQT_QUEUEFLAGS
#define INCLUDED_BMQT_QUEUEFLAGS

//@PURPOSE: Provide enumerators for flags to use at Queue open.
//
//@CLASSES:
//  bmqt::QueueFlags:     flags to use at Queue open
//  bmqt::QueueFlagsUtil: utilities to manipulate queue flags bit-mask values
//
//@DESCRIPTION: This file contains an enum, &#39;bmqt::QueueFlags&#39; of all the flags
// that can be used at Queue open.  Each value of the enum correspond to a bit
// of a bit-mask integer.  It also exposes a set of utilities, in the
// &#39;bmqt::QueueFlagsUtil&#39; namespace to manipulate such bit-mask value.

// BMQ
#include &lt;bmqscm_version.h&gt;

// BDE
#include &lt;bsl_iosfwd.h&gt;
#include &lt;bsl_string.h&gt;
#include &lt;bsls_types.h&gt;

namespace BloombergLP {
namespace bmqt {


                             // =================
                             // struct QueueFlags
                             // =================

struct QueueFlags {
    // This enum represents queue flags

    // TYPES
    enum Enum {
        e_ADMIN  = (1 &lt;&lt; 0) // The queue is opened in admin mode (Valid only
                            // for BlazingMQ admin tasks)
      , e_READ   = (1 &lt;&lt; 1) // The queue is opened for consuming messages
      , e_WRITE  = (1 &lt;&lt; 2) // The queue is opened for posting messages
      , e_ACK    = (1 &lt;&lt; 3) // Set to indicate interested in receiving
                            // &#39;ACK&#39; events for all message posted
    };

    // PUBLIC CONSTANTS
    static const int k_LOWEST_SUPPORTED_QUEUE_FLAG = e_ADMIN;
        // NOTE: This value must always be equal to the lowest type in the
        // enum because it is being used as a lower bound to verify that a
        // QueueFlags field is a supported type.

    static const int k_HIGHEST_SUPPORTED_QUEUE_FLAG = e_ACK;
        // NOTE: This value must always be equal to the highest *supported*
        // type in the enum because it is being used to verify a QueueFlags
        // field is a supported type.


    // CLASS METHODS
    static bsl::ostream&amp; print(bsl::ostream&amp;    stream,
                               QueueFlags::Enum value,
                               int              level = 0,
                               int              spacesPerLevel = 4);
        // Write the string representation of the specified enumeration &#39;value&#39;
        // to the specified output &#39;stream&#39;, and return a reference to
        // &#39;stream&#39;.  Optionally specify an initial indentation &#39;level&#39;, whose
        // absolute value is incremented recursively for nested objects.  If
        // &#39;level&#39; is specified, optionally specify &#39;spacesPerLevel&#39;, whose
        // absolute value indicates the number of spaces per indentation level
        // for this and all of its nested objects.  If &#39;level&#39; is negative,
        // suppress indentation of the first line.  If &#39;spacesPerLevel&#39; is
        // negative, format the entire output on one line, suppressing all but
        // the initial indentation (as governed by &#39;level&#39;).  See &#39;toAscii&#39; for
        // what constitutes the string representation of a
        // &#39;GenericResult::Enum&#39; value.

    static const char *toAscii(QueueFlags::Enum value);
        // Return the non-modifiable string representation corresponding to the
        // specified enumeration &#39;value&#39;, if it exists, and a unique (error)
        // string otherwise.  The string representation of &#39;value&#39; matches its
        // corresponding enumerator name with the &#39;e_&#39; prefix elided.  Note
        // that specifying a &#39;value&#39; that does not match any of the enumerators
        // will result in a string representation that is distinct from any of
        // those corresponding to the enumerators, but is otherwise
        // unspecified.

    static bool fromAscii(QueueFlags::Enum *out, const bslstl::StringRef&amp; str);
        // Return true and fills the specified &#39;out&#39; with the enum value
        // corresponding to the specified &#39;str&#39;, if valid, or return false and
        // leave &#39;out&#39; untouched if &#39;str&#39; doesn&#39;t correspond to any value of
        // the enum.
};

// FREE OPERATORS
bsl::ostream&amp; operator&lt;&lt;(bsl::ostream&amp; stream, QueueFlags::Enum value);
    // Format the specified &#39;value&#39; to the specified output &#39;stream&#39; and return
    // a reference to the modifiable &#39;stream&#39;.


                           // =====================
                           // struct QueueFlagsUtil
                           // =====================

struct QueueFlagsUtil {

  public:
    // CLASS METHODS
    static bool isSet(bsls::Types::Uint64 flags, QueueFlags::Enum flag);
        // Return true if the bit-mask in the specified &#39;flags&#39; has the
        // specified &#39;flag&#39; set, or false if not.
        //
        // DEPRECATED: This method is deprecated in favor of the below more
        //             specific accessors; and should be made private once all
        //             clients have been updated to the new APIs.

  public:
    // CLASS METHODS
    static
    bool isValid(bsl::ostream&amp; errorDescription, bsls::Types::Uint64 flags);
        // Check whether the specified &#39;flags&#39; represent a valid combination of
        // flags to use for opening a queue.  Return true if it does, or false
        // if some exclusive flags are both set, and populate the specified
        // &#39;errorDescription&#39; with the reason of the failure.

    static bsls::Types::Uint64 empty();
        // The &#39;empty&#39; value for flags.

    static bool isEmpty(bsls::Types::Uint64 flags);
        // Returns &#39;true&#39; if the specified &#39;flags&#39; have the &#39;empty&#39; value.

    static bool isReader(bsls::Types::Uint64 flags);
        // Returns &#39;true&#39; if the specified &#39;flags&#39; represent a reader.

    static bool isWriter(bsls::Types::Uint64 flags);
        // Returns &#39;true&#39; if the specified &#39;flags&#39; represent a writer.

    static bool isAdmin(bsls::Types::Uint64 flags);
        // Returns &#39;true&#39; if the specified &#39;flags&#39; represent an admin.

    static bool isAck(bsls::Types::Uint64 flags);
        // Returns &#39;true&#39; if the specified &#39;flags&#39; represent ack required.

    static void setReader(bsls::Types::Uint64 *flags);
        // Sets the specified &#39;flags&#39; representation for reader.

    static void setAdmin(bsls::Types::Uint64 *flags);
        // Sets the specified &#39;flags&#39; representation for admin.

    static void setWriter(bsls::Types::Uint64 *flags);
        // Sets the specified &#39;flags&#39; representation for writer.

    static void setAck(bsls::Types::Uint64 *flags);
        // Sets the specified &#39;flags&#39; representation for ack.

    static void unsetReader(bsls::Types::Uint64 *flags);
        // Resets the specified &#39;flags&#39; representation for reader.

    static void unsetAdmin(bsls::Types::Uint64 *flags);
        // Resets the specified &#39;flags&#39; representation for admin.

    static void unsetWriter(bsls::Types::Uint64 *flags);
        // Resets the specified &#39;flags&#39; representation for writer.

    static void unsetAck(bsls::Types::Uint64 *flags);
        // Resets the specified &#39;flags&#39; representation for ack.

    static bsls::Types::Uint64 additions(bsls::Types::Uint64 oldFlags,
                                         bsls::Types::Uint64 newFlags);
        // Return a new flag mask that only set bits are the ones that are in
        // the specified &#39;newFlags&#39; and not in the specified &#39;oldFlags&#39;.

    static bsls::Types::Uint64 removals(bsls::Types::Uint64 oldFlags,
                                        bsls::Types::Uint64 newFlags);
        // Return a new flag mask that only set bits are the ones that are in
        // the specified &#39;oldFlags&#39; and not in the specified &#39;newFlags&#39;.

    static
    bsl::ostream&amp; prettyPrint(bsl::ostream&amp; stream, bsls::Types::Uint64 flags);
        // Print the ascii-representation of all the values set in the
        // specified &#39;flags&#39; to the specified &#39;stream&#39;.  Each value is &#39;,&#39;
        // separated.

    static int fromString(bsl::ostream&amp;        errorDescription,
                          bsls::Types::Uint64 *out,
                          const bsl::string&amp;   str);
        // Convert the string representation of the enum bit mask from the
        // specified &#39;str&#39; (which format corresponds to the one of the
        // &#39;prettyPrint&#39; method) and populate the specified &#39;out&#39; with the
        // result on success returning 0, or return a non-zero error code on
        // error, populating the specified &#39;errorDescription&#39; with a
        // description of the error.
};

// ============================================================================
//                             INLINE DEFINITIONS
// ============================================================================


                           // ---------------------
                           // struct QueueFlagsUtil
                           // ---------------------

inline
bool
QueueFlagsUtil::isSet(bsls::Types::Uint64 flags,
                      QueueFlags::Enum    flag)
{
    return ((flags &amp; flag) != 0);
}

inline
void
QueueFlagsUtil::setReader(bsls::Types::Uint64 *flags)
{
    *flags |= bmqt::QueueFlags::e_READ;
}

inline
void
QueueFlagsUtil::setAdmin(bsls::Types::Uint64 *flags)
{
    *flags |= bmqt::QueueFlags::e_ADMIN;
}

inline
void
QueueFlagsUtil::setWriter(bsls::Types::Uint64 *flags)
{
    *flags |= bmqt::QueueFlags::e_WRITE;
}

inline
void
QueueFlagsUtil::setAck(bsls::Types::Uint64 *flags)
{
    *flags |= bmqt::QueueFlags::e_ACK;
}

inline
void
QueueFlagsUtil::unsetReader(bsls::Types::Uint64 *flags)
{
    *flags &amp;= ~bmqt::QueueFlags::e_READ;
}

inline
void
QueueFlagsUtil::unsetAdmin(bsls::Types::Uint64 *flags)
{
    *flags &amp;= ~bmqt::QueueFlags::e_ADMIN;
}

inline
void
QueueFlagsUtil::unsetWriter(bsls::Types::Uint64 *flags)
{
    *flags &amp;= ~bmqt::QueueFlags::e_WRITE;
}

inline
void
QueueFlagsUtil::unsetAck(bsls::Types::Uint64 *flags)
{
    *flags &amp;= ~bmqt::QueueFlags::e_ACK;
}

inline
bool
QueueFlagsUtil::isReader(bsls::Types::Uint64 flags)
{
    return isSet(flags, bmqt::QueueFlags::e_READ);
}

inline
bool
QueueFlagsUtil::isWriter(bsls::Types::Uint64 flags)
{
    return isSet(flags, bmqt::QueueFlags::e_WRITE);
}

inline
bool
QueueFlagsUtil::isAdmin(bsls::Types::Uint64 flags)
{
    return isSet(flags, bmqt::QueueFlags::e_ADMIN);
}

inline
bool
QueueFlagsUtil::isAck(bsls::Types::Uint64 flags)
{
    return isSet(flags, bmqt::QueueFlags::e_ACK);
}

inline
bool
QueueFlagsUtil::isEmpty(bsls::Types::Uint64 flags)
{
    return flags == empty();
}

inline
bsls::Types::Uint64
QueueFlagsUtil::empty()
{
    return 0;
}

}  // close package namespace

                            // -----------------
                            // struct QueueFlags
                            // -----------------

inline
bsl::ostream&amp;
bmqt::operator&lt;&lt;(bsl::ostream&amp;          stream,
                 bmqt::QueueFlags::Enum value)
{
    return bmqt::QueueFlags::print(stream, value, 0 , -1);
}

}  // close enterprise namespace

#endif
</pre>
</body>
</html>
